package cn.net.lwj.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component(value="fzbaCommonProperties")
public class CommonPropertites {
	private static Logger log = Logger.getLogger(CommonPropertites.class);
	@Value("${FY_DQ:''}")
	public String FY_DQ;
	@Value("${FY_DQGY:''}")
	public String FY_DQGY;
    @Value("${INIT_FYDM_SQL:''}")
    public String INIT_FYDM_SQL;//获取法院代码名称Map sql
	public static Map<String, String> T_XTPZ_PZXX_MAP;
	public static String SYS_NAME = "";//系统名称
	public static String SYS_TYPE;
	public static String CHARSET;//请求编码
	public static String WITHUB_JOB;
	public static String RUNS = "";
	public static String tq_yxj_1_limit;
	public static String tq_yxj_2_limit;
	public static String tq_yxj_3_limit;
	public static String tq_yxj_4_limit;
	public static String ml_yxj_1_limit;
	public static String ml_yxj_2_limit;
	public static String ml_yxj_3_limit;
	public static String ml_yxj_4_limit;

	public static String qy_czlx_1;
	public static String qy_czlx_2;
	public static String qy_czlx_3;
	public static String qy_czlx_4;
	public static String qy_czlx_5;

	public static String fzba_temtxt_save_url;

	public static String FHWDMLBM_URL;//返回分析后目录的地址
	public static String HQWDWJXX_URL;//获取文件信息地址
	public static String HQTP_URL;//档案系统获取图片地址
	public static String HQCSML_URL;//档案系统获取初始目录地址

	public static String FHSBJG_URL;//档案系统返回识别目录结果地址

	public static String DAXXOCRJGFH_URL;//档案文件OCR识别结果返回


	public static String AJGL_URL;
	public static String AJGL_USERNAME;
	public static String AJGL_PASSWORD;
	
	public static String OCR_URL;
	public static String WS_FILE_URL;

	public static String FTP_URL;
	public static String FTP_PORT;
	public static String FTP_USERNAME;
	public static String FTP_PASSWORD;
	public static String WORD_TEMP_URL;

	public static String YSTQQYBZ;
	public static String SAVE_IN_141;
	public static String WS_FILE_URL_2;

	public static String DAXXSBQYBZ;

	public static AnnotationBeanPostProcessor propertites =null;

	public static String JZIMG_URL;

	public static String AJGLXT_URL;

	public static String MRML;// 自动分目录时，第一张分配的默认目录，可在配置文件修改
	public static String GET_CATALOG_CONFIG_URL; // 获取目录的配置信息地址
	public static String WS_FILE_SERVICE;


	public  static void initConfig(ServletContext sc){
		propertites = (AnnotationBeanPostProcessor) SpringBeanHelper.getBean(sc, "propertyConfigurer");

		SYS_NAME = propertites.getPros("SYS_NAME");

		SYS_TYPE=propertites.getPros("SYS_TYPE");

		CHARSET=propertites.getPros("CHARSET");
		WITHUB_JOB=propertites.getPros("WITHUB_JOB");
		RUNS = propertites.getPros("runs");
		FTP_URL=propertites.getPros("FTP_URL");
		FTP_PORT=propertites.getPros("FTP_PORT");
		FTP_USERNAME=propertites.getPros("FTP_USERNAME");
		FTP_PASSWORD=propertites.getPros("FTP_PASSWORD");
		WORD_TEMP_URL=propertites.getPros("WORD_TEMP_URL");

		tq_yxj_1_limit=propertites.getPros("tq_yxj_1_limit");
		tq_yxj_2_limit=propertites.getPros("tq_yxj_2_limit");
		tq_yxj_3_limit=propertites.getPros("tq_yxj_3_limit");
		tq_yxj_4_limit=propertites.getPros("tq_yxj_4_limit");

		ml_yxj_1_limit=propertites.getPros("ml_yxj_1_limit");
		ml_yxj_2_limit=propertites.getPros("ml_yxj_2_limit");
		ml_yxj_3_limit=propertites.getPros("ml_yxj_3_limit");
		ml_yxj_4_limit=propertites.getPros("ml_yxj_4_limit");

		fzba_temtxt_save_url=propertites.getPros("fzba_temtxt_save_url");
		qy_czlx_1=propertites.getPros("qy_czlx_1");
		qy_czlx_2=propertites.getPros("qy_czlx_2");
		qy_czlx_3=propertites.getPros("qy_czlx_3");
		qy_czlx_4=propertites.getPros("qy_czlx_4");
		qy_czlx_5=propertites.getPros("qy_czlx_5");

		FHWDMLBM_URL=propertites.getPros("FHWDMLBM_URL");
		HQWDWJXX_URL=propertites.getPros("HQWDWJXX_URL");
		HQTP_URL=propertites.getPros("HQTP_URL");
		HQCSML_URL=propertites.getPros("HQCSML_URL");

		FHSBJG_URL=propertites.getPros("FHSBJG_URL");

		DAXXOCRJGFH_URL=propertites.getPros("DAXXOCRJGFH_URL");

		AJGL_URL=propertites.getPros("AJGL_URL");
		AJGL_USERNAME=propertites.getPros("AJGL_USERNAME");
		AJGL_PASSWORD=propertites.getPros("AJGL_PASSWORD");
		OCR_URL=propertites.getPros("OCR_URL");
		WS_FILE_URL=propertites.getPros("WS_FILE_URL");
		WS_FILE_SERVICE = propertites.getPros("WS_FILE_SERVICE");
		T_XTPZ_PZXX_MAP = getTxtpzPzxxMap(sc);

		YSTQQYBZ=propertites.getPros("YSTQQYBZ");
		SAVE_IN_141=propertites.getPros("SAVE_IN_141");
		WS_FILE_URL_2=propertites.getPros("WS_FILE_URL_2");
		DAXXSBQYBZ=propertites.getPros("DAXXSBQYBZ");
		JZIMG_URL = propertites.getPros("JZIMG_URL");
		T_XTPZ_PZXX_MAP.put("JZIMG_URL",JZIMG_URL);
		log.info("SYS_NAME=="+SYS_NAME);
		log.info("JZIMG_URL------------"+JZIMG_URL);
		AJGLXT_URL = propertites.getPros("AJGLXT_URL");

		MRML = propertites.getPros("MRML");
		GET_CATALOG_CONFIG_URL = propertites.getPros("GET_CATALOG_CONFIG_URL");
	}

	//al导入的
	/**
	 * 角色(对应系统平台)
	 */
	@Value("${XTPT_BUSINESS_ID:''}")
	public String XTPT_BUSINESS_ID;
	@Value("${XTPT_WEBSERVICE_URL:''}")
	public String XTPT_WEBSERVICE_URL;
	@Value("${AJGL_WEBSERVICE_URL:''}")
	public  String AJGL_WEBSERVICE_URL;
	//获取class路径
	public static String getClassPath(){
		String path = CommonPropertites.class.getResource("/").getPath();
		path = path.substring(1,path.length()-1);//去掉前后两个斜杠/

		Properties prop = System.getProperties();

		String os = prop.getProperty("os.name");
		//判断操作系统
		//log.info("os...."+os);
		if(os.startsWith("win") || os.startsWith("Win")){
			//windows
		}else{
			//other
			path = "/"+path;
		}

		return path;
	}
	public static String getWebRootPath(){
		String path = getClassPath();
		if(path.indexOf("target")>-1){
			path = path.substring(0,path.length()-"/target/classes".length())+"";///src/main/webapp
		}else if(path.indexOf("WEB-INF")>-1){
			path = path.substring(0,path.length()-"/WEB-INF/classes".length());
		}

		Properties prop = System.getProperties();

		String os = prop.getProperty("os.name");
		//判断操作系统
		//log.info("os...."+os);
		if(os.startsWith("win") || os.startsWith("Win")){
			//windows
		}else{
			//other
			path = "/"+path;
		}

		return path;
	}

	//初始化数据库保存的系统变量
    public static Map<String, String> getTxtpzPzxxMap(ServletContext sc) {
        Map<String, String> map = new HashMap<String, String>();
        //-------如果配置文件里面有值，读取配置文件--------------------------------
        String proRed="ACT_SERVER_PATH,ACTSERVER_IMG_PATH,FLOW_CHECK_SYS,FLOW_CHECK_URL,WS_SERVER_PATH,WSSW_FTP_SERVER_IP,WS_TEMP_PATH,WS_WINDOWS_SERVER_PATH,WS_SERVER_TYPE,FILE_SERVER_PATH,XTBSHJ_TYPE,WITHUB_JOB,HQWDWJXX_URL,FHWDMLBM_URL,,AJGL_URL,AJGL_USERNAME,AJGL_PASSWORD,OCR_URL,fzba_temtxt_save_url,JdbcToolName_M00,JdbcToolName_M10";
        String[] a=proRed.split(",");
        for(int i=0;i<a.length;i++){
        	if(propertites.getPros(a[i])!=null&&!propertites.getPros(a[i]).trim().equals(""))
        		map.put(a[i], propertites.getPros(a[i]).toString().trim());
        }
        return map;
    }
    
  //取配置的变量值
    public static String getPropertites(String id, String fydm) {
		String blz = null;
		try {
			blz = "";
			if ("".equals(fydm)) blz = T_XTPZ_PZXX_MAP.get(id) == null ? "" : T_XTPZ_PZXX_MAP.get(id).toString().trim();
            else {
                if (T_XTPZ_PZXX_MAP.get(id + "_" + fydm) != null) {
                    blz = T_XTPZ_PZXX_MAP.get(id + "_" + fydm) == null ? "" : T_XTPZ_PZXX_MAP.get(id + "_" + fydm).toString().trim();
                } else {
                    blz = T_XTPZ_PZXX_MAP.get(id) == null ? "" : T_XTPZ_PZXX_MAP.get(id).toString().trim();
                }
            }
			if (blz == null) blz = "";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return blz;
    }
    
  //取配置的变量值
    public static String getPropertites(String id) {
        String blz = "";
        blz = getPropertites(id, "");
        return blz;
    }
    
}
